package com.admin.business.portalWebsite.venusSysUserPayment;

import com.tiangong.framework.annotation.OpenApi;
import com.tiangong.framework.bo.CDO;
import com.tiangong.framework.bo.Return;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

/**
 * @description: 付费查看专家问题记录
 * @create: 2023-11-18 16:45:42
 **/
@Service("venusSysUserPaymentService")
@Slf4j
public class VenusSysUserPaymentService{

    @Resource
    VenusSysUserPaymentDao venusSysUserPaymentDao;

    /**
     * 添加付费查看专家问题记录,获取id数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:用户ID
     *                   - record_id:专家问题ID
     *                   - payment_amount:付费金额
     *                   - begin_time:开始时间
     *                   - update_time:更新时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return addVenusSysUserPayment(CDO cdoRequest) {
        venusSysUserPaymentDao.addVenusSysUserPayment(cdoRequest);
        CDO cdoResult = new CDO();
        if (cdoRequest.containsKey("id")) {
            cdoResult.set("id", cdoRequest.get("id"));
        }
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据id，更新付费查看专家问题记录数据
     *
     * @param cdoRequest - id:主键
     *                   - user_id:用户ID
     *                   - record_id:专家问题ID
     *                   - payment_amount:付费金额
     *                   - begin_time:开始时间
     *                   - update_time:更新时间
     *                   - state:是否删除：0、正常，1、已删除；
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return updateVenusSysUserPaymentById(CDO cdoRequest) {
        venusSysUserPaymentDao.updateVenusSysUserPaymentById(cdoRequest);
        return Return.SUCCESS;
    }

    /**
     * 根据id，删除付费查看专家问题记录数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return deleteVenusSysUserPaymentById(CDO cdoRequest){
        int count = venusSysUserPaymentDao.deleteVenusSysUserPaymentById(cdoRequest.getString("id"));
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据条件，删除付费查看专家问题记录数据
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return deleteVenusSysUserPayment(CDO cdoRequest) {
        int count = venusSysUserPaymentDao.deleteVenusSysUserPayment(cdoRequest);
        CDO cdoResult = new CDO();
        cdoResult.set("count", count);
        return Return.valueOf(cdoResult);
    }

    /**
     * 根据ID，获取付费查看专家问题记录数据
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysUserPaymentById(CDO cdoRequest) {
        CDO cdoMapperResult = venusSysUserPaymentDao.getVenusSysUserPaymentById(cdoRequest.getString("id"));
        return Return.valueOf(cdoMapperResult);
    }

    /**
     * 根据非空条件，获取付费查看专家问题记录数据列表
     *
     * @param cdoRequest
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysUserPaymentListPage(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysUserPaymentDao.getVenusSysUserPaymentListPage(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysUserPaymentDao.getVenusSysUserPaymentCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
    /**
     * 根据混合条件，获取付费查看专家问题记录数据列表
     *
     * @param cdoRequest - id:主键
     * @return
     * @author wdf
     * @create: 2023-11-18 16:45:42
     */
    @OpenApi
    public Return getVenusSysUserPaymentListPageByCondition(CDO cdoRequest) {
        Integer pageIndex = cdoRequest.getInteger("pageIndex")-1;
        int recordSize = 10;
        cdoRequest.set("recordFrom", pageIndex * recordSize);
        cdoRequest.set("recordSize", recordSize);
        List<CDO> cdoMapperResultList = venusSysUserPaymentDao.getVenusSysUserPaymentListPageByCondition(cdoRequest);
        boolean isEndPage = false;
        if (cdoMapperResultList.size() < recordSize) {
            isEndPage = true;
        }
        CDO cdoResult = new CDO();
        cdoResult.set("isEndPage", isEndPage);
        cdoResult.set("datalist", cdoMapperResultList);
//        int total = venusSysUserPaymentDao.getVenusSysUserPaymentCount(cdoRequest);
//        cdoResult.set("total", total);
        return Return.valueOf(cdoResult);
    }
}
